<!DOCTYPE html>
<html lang="en">
<head>
	<title>AudioMass - About</title>
	<meta charset="utf-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1"/>  

	<meta name="description" content="AudioMass is a free full-featured web-based audio &amp; waveform editing tool"/>
	<meta property="og:image" content="https://audiomass.co/icon.jpg"/>
	<meta property="og:title" content="AudioMass">
	<meta property="og:url" content="https://audiomass.co/">
	<meta property="og:description" content="AudioMass is a free full-featured web-based audio &amp; waveform editing tool">
	<meta name="keywords" content="AudioMass, WebAudio, WaveForm, audio editing, free audio editing, audio tool, waveform editor, sound editor, open source">
	<link href="/audiomass/ico.ico" rel="shortcut icon">

<style>
	body{
		padding:0;margin:0;
		font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
		color:rgb(5, 10, 5);
		background:#fefefe
	}
	#w{
		width: 90%;
		max-width:960px;
		margin:0 auto
	}

	#w > div{
		padding:20px 0 0 0
	}

	p{
		line-height:21px;
		font-size:16px;
		margin-bottom:1.2em
	}

	h1{
		font-size: 26px;
		margin-top:35px
	}

	h5{
		font-size:1em;
		margin-bottom:0
	}

	.top{
		max-width:100%;
		outline:0;
		display:inline-block
	}

	.mid{
		max-width:504px;
		width: 90%;
		outline:0;
		margin-bottom:16px;
		display:inline-block
	}

	.nomarg{
		margin-bottom:0
	}

	pre {
	    padding:12px 16px;
	    display:inline-block;
	    border-radius:6px;
	    background:#e1f3e9;
	    text-shadow:0 1px #fff;
	    border-bottom:1px solid #aaa;
	    max-width:90%;
	    overflow:scroll
	}

	ul {
		padding:0;
		list-style:none
	}

	li {
		padding:0 0 3px 0;
		color:#333;
		font-size:0.92em
	}

	video {
		max-width:660px;
		width:90%;
	}

	::-moz-selection { background: #080808; color:#fff; text-shadow:none }
	::selection { background: #080808;  color:#fff; text-shadow:none }
</style>
</head>
<body>
<div id="w">


<div>
<h1>Introducing AudioMass (<a href="https://audiomass.co" target="_blank">https://audiomass.co</a>) an open-source web based audio and waveform editing tool.</h1>


<img class="top" src="/audiomass/about/audiomass_top.jpg" />


<p>AudioMass lets you record, or use your existing audio tracks, and modify them by trimming, cutting, pasting or applying a plethora of effects, from compression and paragraphic equalizers to reverb, delay and distortion fx. AudioMass also supports more than 20 hotkeys combinations and a dynamic responsive interface to ensure ease of use and that your producivity remains high.
it is written solely in plain old-school javascript, weights approximately 65kb and has no backend or framework dependencies.</p>

<img class="mid" src="/audiomass/about/audiomass_support.jpg" />
<p>It also has very good browser and device support.</p>


<h5>:: Feature List ::</h5>

<ul>
<li>Loading Audio, navigating the waveform, zoom and pan</li>
<li>Visualization of frequency levels</li>
<li>Peak and distortion signaling</li>
<li>Cutting/Pasting/Trimming parts of the audio</li>
<li>Inverting and Reversing Audio</li>
<li>Exporting to mp3</li>
<li>Modifying volume levels</li>
<li>Fade In/Out</li>
<li>Compressor</li>
<li>Normalization</li>
<li>Reverb</li>
<li>Delay</li>
<li>Distortion</li>
<li>Pitch Shift</li>
<li>Keeps track of states so you can undo mistakes</li>
<li>Offline support!</li>
</ul>

<p>And all this, in only 83kb of JS!</p>
</div>


<div>
<h3>Getting Started</h3>


<p>To get started, drag and drop an audio file, or try the included sample.<br />
Once the file is loaded and you can view the waveform, zoom in, pan around, or select a region.</p>

<img class="mid" src="/audiomass/about/audiomass_2.jpg" />


<h3>Recording Audio</h3>

<p>To record audio, simply press the Recording button, or the <i>[R]</i> key.</p>

<img class="mid" src="/audiomass/about/audiomass_3.jpg" />


<h3>Exporting to mp3</h3>

<p>In order to export back to mp3, click on 'File', then 'Export to mp3', and follow the modal's instructions.</p>

<img class="mid" src="/audiomass/about/audiomass_4.jpg" />

</div>


<hr />


<div>
<h3>The story behind AudioMass. And a short rant on web interfaces.</h3>

<p>I wrote AudioMass back in June 2018 and it stayed dormant on my hard disk until I decided to share it with the world today (July 13th, 19 -- but you might be seeing this in 2020. Hi!!).
It started as a personal small tool for quick visualization of waveforms. Later I added the ability to cut/copy/paste as well as fade in and out. And soon after good 'ol feature creep and perfectionism took over! Soon after, it turned to a challenge to see how close to a full-featured waveform editor it can get, whilst maintaining acceptable performance and small filesize.</p>

<p>In general I am a big fan of the interfaces of DAWs <i>(Digital Audio Workstations)</i>, they are extremely, complex, intricate, versatile, and they manage to remain visually pleasant even through their infinite options and knobs. Many times I feel the web has taken a very wrong turn, as amazing interfaces such as...

<p class="nomarg">Sonar</p>
<img class="mid" src="/audiomass/about/sonar.jpg" />

<br />
<p class="nomarg">Fruity loops</p>
<img class="mid" src="/audiomass/about/fruity.png" />

<br />

<p>Existed for more than 10-15 years now, while we are struggling with animating some rectangles for 60fps... So for AudioMass I wanted to try and make a fast and performant interface. Drawing inspiration from the examples I mentioned earlier rather than the tradiional web development practices. This is my unconvincing but truthfull excuse as to why the code is ugly; it is focused on being fast and getting the job done, with little regard on structure.</p>

</div>

<hr />

<div>

<h3>Building the interface</h3>

<p>Let's say we have a <i>"PLAY"</i> button and when we press it the track begins to play. I suppose we would want the button's color and state to reflect that the track is now playing. So naively we would do something like;</p>


<pre><code>btn.onclick = function () {
	this.classList.add ('active');
};</code></pre>

<p>But what happens if we have a hotkey that triggers the same action? Let's say we press <i>[SPACEBAR]</i> and the track begins to play. Do we modify that button's class in the spacebar's handler?</p>

<pre><code>document.onkeypress = function ( e ) { 
  if ( e.keyCode === 32) {
       e.preventDefault ();

       document.querySelector ('.playbtn').classList.add ('active');
  }
};</code></pre>

<p>And what happens, if there are 2 buttons, or one gets dynamically removed? Do we do selectAll and iterate? Hmmm...<br />
And if the track is playing and we hit <i>[SPACEBAR]</i> or the play button again, we need to stop playing. What do we do then? You can see how this becomes messy very quickly as everything gets very tighlty coupled together in a big dependency ball.</p>



<p>Introducing the observer pattern. Actions are represented by events. So the above logic and be expressed as;</p>


<pre><code>btn.onclick = function () {
	FireEvent ('RequestTogglePlay');
};

On ('WillPlay', function () {
	btn.classList.add ('active');
});

On ('WillStop', function () {
	btn.classList.remove ('active');
});



document.onkeypress = function ( e ) {
  if ( e.keyCode === 32) {
       e.preventDefault ();

       FireEvent ('RequestTogglePlay');
  }
};



On ('RequestTogglePlay', function () {
	if (track.is_playing) {
		FireEvent ('WillStop');
		track.stop ();
	}
	else {
		FireEvent ('WillPlay');
		track.play ();
	}
});

track.onPlayStart = function () {
	FireEvent ('DidPlay');
};
track.onPlayStop = function () {
	FireEvent ('DidStop');
};
</code></pre>

<p>Now this is completely decoupled and dependency free! The button will set its state according to the events it receives, and both the button and the spacebar key rely on the same mechanisms.
You may notice the vocabulary we are using. <i>"Request"</i>, <i>"Will"</i> and <i>"Did"</i>. These are arbitrarilly chosen to impose some extra structure.<br /> <i>"Request"</i> denotes intent to perform an action, it is not guaranteed that the action will execute as there might be conditions preventing it (eg unitialized or still loading objects). <i>"Will"</i> means that the conditions passed and we are attempting to perform the action. And <i>"Did"</i> means that the action just got performed.<br />
It might be a bit too verbose, but it worked very well for structuring AudioMass's interface.</p>
</div>

<hr />

<div>
<h3>Dockable UI</h3>

<p>One thing I love about DAW interfaces, is that every window can be pulled out of the main host. I fondly remember having 3 screens full of VST plugins. So can we do the same in the browser?</p>


<video src="/audiomass/about/dock_ui.mp4" autoplay muted playsinline controls loop></video>


<p>Yes! And it is using some of the oldest tricks in the book. Essentially we create a pop-up window with <i>window.open</i> and just pass buffers to its <i>documentWindow</i> object. Surprisingly it is quite performant on all browsers except IE Edge. I believe they are serializing in ascii or base64 every packet or something. Also Chrome has an interesting bug where you can't pass more than 512 byte buffers.</p>

<p>So for the undocked window, we call <i>window.open</i>. But how do we make it work when it is docked? It would be quite cumbersome to write the same functionality twice, once as a standalone page, and once as an in-page script. Luckily we can avoid that completely, and re-use the same page by using iframes.</p>

<p>The only difference is that the undocked version uses <i>window.opener</i> to refference its parent, whereas the iframe uses <i>window.parent</i>.</p>

</div>


<hr />

<div>
<h3>Future work and performance considerations</h3>

<p>The next big feature that is planned, is multitrack support. The ability to mix tracks and different sounds is currently lacking and its usefulness as it stands is limited.</p>

<hr />

<p>There is also a lot of room for improvement in almost all aspects.</p>

<p>First of all we can further reduce the filesize by around 20kb by removing the library we are using for rendering the waveform. We use only a fraction of its functionality so there is no reason to include it all.</p>

<p>We can also optimize a lot the rendering of the waveform. I heavily modified the library used to compute and draw only the visible range. However it is still clearing and re-drawing all of the canvas at each frame. We can take advantage of 2d Context's translate calls, and shift the canvas around instead of redrawing all of the pixels.</p>

<p>We can also move some operations to a background thread, such as the filters processing so that the UI does not freeze when applying a long chain of effects.</p>

<br />


<p>However, the biggest issue I encountered, is the Web Audio API itself. Every operation results in iterating over multiple long arrays per frame. Eventually the garbage collector fires and crackling is introduced. Only way to go around this is to use a small fftSize, but then the frequency range we have to work with is very narrow. Perhaps a pure WASM implementation would outperform trying to modify audio signals with JS. Only one way to find out I guess :) </p>
<p>Additionally, <i>decodeAudioData</i> provides no progress callback, and no way of cancelling it. So if you attempt to load a huge audio file, you will waste resources until it gets processed. There is no way around this currently and it can get annoying if you push a big file by mistake.</p>

</div>

<br /><br /><br />

</div>
</body>

</html>